# Cookies_with5Chips.py # # Description: Draws a chocolate chip cookie with our turtle. # # Anne Lavergne # Date: Feb. 26 2024 # Import the turtle library import turtle # Function to draw a chocolate chip cookie def drawCookie(aTurtle,aX,aY,aRadius,listOfColours): """Draw a chocolate chip cookie.""" # Draw the contour of the cookie aTurtle.penup() aTurtle.goto(aX,aY) aTurtle.pendown() aTurtle.circle(aRadius) aTurtle.penup() # Compute the centre (x,y) of the cookie centreX = aX centreY = aY+radius index = 0 for chip in ((0,0),(-10,10),(-15,-10),(20,-15),(12,15)): # Move the turtle to the chocolate chip location aTurtle.goto(centreX+chip[0],centreY+chip[1]) # Using colour at index "index" in the "listOfColours" aTurtle.color(listOfColours[index]) # Draw a chocolate chip in the cookie aTurtle.stamp() # Go to next colour index += 1 return # Creates a graphics window - canvas canvas = turtle.Screen() # Create a turtle named tt tt = turtle.Turtle() # Set radius radius = 30 # Set the colours of the 5 chips theColours = ('saddlebrown','pink','yellow','green','red') # Draw cookies for location in ((-140,-120), (100,75), (0,0), (-68,100)): drawCookie(tt, location[0], location[1], radius, theColours) tt.color('black') # Click on the canvas to exit canvas.exitonclick()